var formId = "#formsubject";
var prefix = "/api/grade/teacher/subject";
var trueParentObj;//真正的父对象的表格
var myEdit;

//增加或更新表单按钮
function insertOrUpdateForm(){
    myEdit.insertOrUpdateForm();//更新当前结点，真正的方法
}
//毕业设计下拉列表
function initgrdesgin(item){

    if(item==null){
        item ={}
    }
    var teacherFormater=function(data){
        return data.username+"/"+data.name;
    }
    Tms.select2AjaxData("/api/grade/dimgraprj/getAll",
        "#thNum", "thNum", "gradeName",item.thNum);

    Tms.select2AjaxData("/api/grade/teacher/getAll",
        "#teacherId", "id", "name", item.teacherId,null,teacherFormater);


    Tms.select2AjaxData("/api/system/sysdict/queryByType?type=profession_type",
        "#professionType", "value", "name", item.professionType);

    //课题类型
    Tms.select2AjaxData("/api/system/sysdict/queryByType?type=subject_type",
        "#subjectType", "value", "name", item.subjectType);


    //课题来源
    Tms.select2AjaxData("/api/system/sysdict/queryByType?type=subject_from",
        "#subjectFrom", "value", "name", item.subjectFrom);


    //学生

    Tms.select2AjaxData("/api/grade/student/getAll",
        "#studentId", "id", "name", item.studentId,null,teacherFormater);

    //第二导师

    Tms.select2AjaxData("/api/grade/teacher/getAll",
        "#secondTutor", "id", "name", item.secondTutor,null,teacherFormater);

    //课题类型
    Tms.select2AjaxData("/api/system/sysdict/queryByType?type=select_type",
        "#selectType", "value", "name", item.selectType);


}


$(function () {
    var isNew = GetQueryString("isNew");
    var hidId = GetQueryString("id");
    // if(hidId==0){
    //     isNew=true
    // }
    var parentName = GetQueryString("parentname");
    var rootText = decodeURI(GetQueryString("rootText"));

    $("#hidId").val(hidId);

    var options = {
        ctrfix: "/grade/subject/teacher",//当前控制器

        getURL: function(id){
            return prefix + "/get?id=" + id;
        },
        saveURL: function(){
            return prefix + "/save";
        },
        updateURL: function(){
            return prefix + "/update";

        },

        saveBefore: function(){
            //保存前
            return true;
        },
        updateBefore: function(){
            //更新前
            return true;
        },
        saveAfter: function (rs) {
            //保存后
        },
        updateAfter: function (rs) {
            //更新后
        },
        showAddBefore : function () {
            //新增对话框打开前
            initgrdesgin()
        },
        showAddAfter:function () {
            //新增对话框打开后
        },
        showUpdateBefore : function () {
            //更新对话框打开前

        },
        showUpdateAfter: function (rs) {
            //更新对话框打开后
            initgrdesgin(rs.data)
        }
    }

    myEdit = new editModel(options);
    myEdit.init(isNew,hidId,parentName,rootText);



    var parentTag = GetQueryString("tag");
    trueParentObj = top.tabArr[parentTag];



})